package com.timefreer.xml.reader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FilesCrawler {

    private List<String> fileNameList;
    private String       suffix = ".xml";

    public List<String> getFileNameList() {
        return fileNameList;
    }

    public void setFileNameList(List<String> fileNameList) {
        this.fileNameList = fileNameList;
    }

    public void refreshFileList(String strPath) {
        File dir = new File(strPath);
        File[] files = dir.listFiles();

        if (files == null || files.length <= 0) return;
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                refreshFileList(files[i].getAbsolutePath());
            } else {
                if (files[i].getAbsolutePath() == null || !files[i].getAbsolutePath().endsWith(suffix)) {
                    continue;
                }
                if (fileNameList == null) {
                    fileNameList = new ArrayList<String>();
                }
                fileNameList.add(files[i].getAbsolutePath());
            }
        }
    }
}
